from socket import *
from common.simple_http_server import SimpleHTTPRequestHandler
__all__ = ["RecipeHTTPRequestHandler"]
class RecipeHTTPRequestHandler(SimpleHTTPRequestHandler):
    search_results = []                            
    def upload_file(self):    
        if self.fs['filepath'].value:
            file = open(self.fs['filepath'].value, 'rb')
        else:                    
            file = self.fs['fileinput'].file
        file_name = self.fs['filename'].value
        self.server.obj.create_recipe_from_file(file, file_name)
        self.messages.append("File uploaded!")
    
    def search(self):
        rs = self.server.obj
        query = self.fs['query'].value
        self.search_results = rs.search(query) 
        
          
              
    